package org.wang.generalcode.support.sm4;

import com.ulisesbocchio.jasyptspringboot.EncryptablePropertyResolver;

public class SM4EncryptablePropertyResolver implements EncryptablePropertyResolver {

    private SM4EncryptablePropertyDetector sm4EncryptablePropertyDetector;

    public SM4EncryptablePropertyResolver(SM4EncryptablePropertyDetector sm4EncryptablePropertyDetector) {
        this.sm4EncryptablePropertyDetector = sm4EncryptablePropertyDetector;
    }


    @Override
    public String resolvePropertyValue(String s) {
        /**
         * 判断是否需要解密，如果需要解密则返回解密以后的值
         */
        if (sm4EncryptablePropertyDetector.isEncrypted(s)) {
            return SM4Utils.decryptStr(s);
        }
        return s;
    }
}
